package com.fernfx.xingtan.main.presenter;

import com.fernfx.xingtan.common.base.BaseIRequestCallback;
import com.fernfx.xingtan.common.network.entity.NetworkOKResult;
import com.fernfx.xingtan.main.contract.RobredPacketHistroyContract;
import com.fernfx.xingtan.main.entity.RobredPacketHistroyEntity;
import com.fernfx.xingtan.main.model.RobredPacketHistoryModel;
import com.fernfx.xingtan.utils.FastJsonUtil;
import com.fernfx.xingtan.utils.OtherUtil;
import com.fernfx.xingtan.utils.ToastUtil;

import java.util.Map;

/**
 * Created by admin on 2018/8/10.
 */

public class RobredPacketHistoryPresenter<P extends RobredPacketHistroyContract.View> implements RobredPacketHistroyContract.Presenter {
    private P P;
    private RobredPacketHistroyContract.Model model;

    @Override
    public void init(RobredPacketHistroyContract.View view) {
        this.P = (P) view;
        this.model = new RobredPacketHistoryModel();
    }

    @Override
    public void sendRobredPacketHistroy(Map<String, Object> requestArgsMap,String url) {
        model.sendRobredPacketHistroy(url,requestArgsMap, new BaseIRequestCallback() {
            @Override
            public void onSuccessful(NetworkOKResult result) {
                String message = result.getMessage();
                RobredPacketHistroyEntity robredPacketHistroyEntity = FastJsonUtil.fromBean(message, RobredPacketHistroyEntity.class);
                if (OtherUtil.checkRequestStatus(robredPacketHistroyEntity)) {
                    P.showRobredPacketHistroy(robredPacketHistroyEntity.getObj().getRecords());
                }else {
                    ToastUtil.showCentertoast(robredPacketHistroyEntity.getMsg());
                }
            }
        });
    }
}
